package com.xmg.p2p.base.service.impl;

import com.xmg.p2p.base.domain.RealAuth;
import com.xmg.p2p.base.event.RealAuthSuccessEvent;
import com.xmg.p2p.base.event.RechargeOfflineSuccessEvent;
import com.xmg.p2p.base.service.ISmsService;
import com.xmg.p2p.business.domain.RechargeOffline;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements ApplicationListener<ApplicationEvent>, ISmsService {
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof RealAuthSuccessEvent) {
            RealAuth realAuth = ((RealAuthSuccessEvent) event).getRealAuth();
            sendSms(realAuth);
        } else if (event instanceof RechargeOfflineSuccessEvent) {
            RechargeOffline rechargeOffline = ((RechargeOfflineSuccessEvent) event).getRechargeOffline();
            sendSms(rechargeOffline);
        }
    }
    private void sendSms(RealAuth realAuth){
        System.out.println(realAuth.getApplier().getUsername()+"实名认证成功,发送短信");
    }
    private void sendSms(RechargeOffline rechargeOffline){
        System.out.println(rechargeOffline.getApplier().getUsername()+"线下充值成功");
    }
}
